using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Scene;
using System;
using System.IO.IsolatedStorage;
namespace MicroMsg.Storage
{
	public class HeadImgStorage
	{
		public void save(string usrName, byte[] imageBuf)
		{
			if (!string.IsNullOrEmpty(usrName) && imageBuf != null && imageBuf.Length > 0)
			{
				ServiceCenter.asyncExec(delegate
				{
					try
					{
						using (IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication())
						{
							string path = this.getPath(usrName);
							if (userStoreForApplication.FileExists(path))
							{
								userStoreForApplication.DeleteFile(path);
							}
							IsolatedStorageFileStream isolatedStorageFileStream = userStoreForApplication.CreateFile(path);
							isolatedStorageFileStream.Write(imageBuf, 0, imageBuf.Length);
							isolatedStorageFileStream.Dispose();
						}
						EventCenter.postCombineEvent(EventConst.ON_STORAGE_HEAD_IMG_ADD, usrName);
					}
					catch (Exception ex)
					{
						Log.smethod_1("HeadImgStorage", string.Concat(new object[]
						{
							"add head image error ",
							usrName,
							" ",
							ex
						}));
					}
				});
				return;
			}
		}
		private static bool isQQUserName(string usrName)
		{
			return usrName.EndsWith("@qqim");
		}
		public virtual string getPath(string userName)
		{
			if (string.IsNullOrEmpty(userName))
			{
				return null;
			}
			return StorageIO.getHeadImgPath() + "/" + userName + ".jpg";
		}
		public bool exist(string usrName)
		{
			if (string.IsNullOrEmpty(usrName))
			{
				return false;
			}
			bool result;
			using (IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication())
			{
				result = userStoreForApplication.FileExists(this.getPath(usrName));
			}
			return result;
		}
		public bool method_0(string usrName)
		{
			if (string.IsNullOrEmpty(usrName))
			{
				return false;
			}
			try
			{
				using (IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication())
				{
					userStoreForApplication.DeleteFile(this.getPath(usrName));
				}
			}
			catch (Exception)
			{
			}
			return true;
		}
		public void dumpData()
		{
			IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
			string[] fileNames = userStoreForApplication.GetFileNames(StorageIO.getHeadImgPath() + "/*");
			for (int i = 0; i < fileNames.Length; i++)
			{
				string text = fileNames[i];
				Log.smethod_5("storage", "img file " + text);
			}
			userStoreForApplication.Dispose();
		}
	}
}
